/*Copyright 2009-2010 by Ward, David J ( pymethius@ominian.net )
Licensed work, all rights reserved.*/
Ext.namespace("wm");
Ext.namespace("wmlib");


wmlib.ureg = function(){
    var self = this;
    
    var myRecord = Ext.data.Record.create([
        {name: "name"},
        {name:"details"}
    ])
    
    var myStore = new Ext.data.Store({})

    //TODO - There is a much better way to do this with ExtJS but this works for now
    jQuery("head").append("<style> #uRegList dt { overflow: visible; white-space: normal }</style>");
    
    var uRegList = {
        id: "uRegList",
        xtype: "listview",
        multiSelect: false,
        emptyTest: "No users",
        reserveScrollOffset: true,
        autoScroll: true, //Apparently this does nothing here
        store: myStore,
        columns: [
                {
                    header: "User Name",
                    width: "40%",
                    dataIndex: "name"
                },
                {
                    header: "Details",
                    width: "55%",
                    dataIndex: "details"
                }
            ]
    };
    
    
    var handleResponse = function(data){
        
        wmlog.debug("UserRegistry - Response was " , data)
        
        //toDisplay = data.result.escapeHTML().sub("\n","<br>\n",100)
        //myStore.add( new myRecord({eventTS:"Now", eventResponse: toDisplay }))
        
    }
    
    var requestHandler = function(msg){
        //This should be an incoming request
        wmlog.info("UserRegistry - request" , msg);
        
        //toDisplay = String.escapeHTML(msg.params);
        //myStore.add( new myRecord({eventTS: "Now", eventResponse: toDisplay}));
        
    }
      
    
    var main = new Ext.Window({
        id : "uReg",
        title : "User registry",
        layout: "anchor",
        minWidth: 450,
        width: 450,
        minHeight: 225,
        height: 400,
        items: [uRegList]        
    })
    
    

    
    
    self.run = function(manager){
        wm.router.modules['ureg'] = requestHandler;
        wm.router.sendMessage("auth.ureg", "ready")
        main.show()
    }
    
    self.stop = function(){
        delete wm.router.modules['ureg'];
        main.hide()
    }
    
    wm.sys.register("User Registry", self);
}

Ext.onReady(function(){
    wm.loader.notify("ureg");
    new wmlib.ureg();
})